package com.ttl.bc.ic.stklocation.action;



import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;
import org.apache.struts.actions.DispatchAction;

import com.ttl.bc.ic.stklocation.db.StkLocationBO;
import com.ttl.common.util.CommonUtils;

public class StkLocationAction extends DispatchAction {

	
	@SuppressWarnings("unchecked")
	public ActionForward show(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) 
			throws Exception {
					
		String user 	 = (String)request.getSession().getAttribute("userName");
		System.out.println(CommonUtils.getDateTimeForStamp()+" #user:"+user+" #use :StkLocationAction #mode :show");
		
		StkLocationBO bo = new StkLocationBO();			
		ArrayList results = (ArrayList)bo.find(request);		
//		request.getSession().setAttribute("results", results);
		
		
		request.getSession().setAttribute("results", results);				
		request.getSession().setAttribute("item", request.getParameter("item"));
		
		return mapping.findForward("success_show");
	}
	
	public ActionForward find(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) 
			throws Exception {
							
		DynaActionForm f = (DynaActionForm) form;		
		String itemFind = new String(f.get("itemFind").toString().getBytes("ISO8859_1"),"UTF-8");
														
		String hql = "FROM BCItemBean WHERE (code like '%"+itemFind+"%' or name1 like '%"+itemFind+"%' ) " +
						" and (code like '2-%' or code like '3-%' )" +
						" ORDER BY code";
		new StkLocationBO().setPage(request, hql);
		
		request.setAttribute("itemFind", itemFind);
		
		return mapping.findForward("success_find");
	}	
}
